/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');
    app.useModule("ui.table");
    var datepicker = require('datepicker');
    var toastr =require('toastr');
    app.controller('recallCtrl', ['$scope','$http','$filter',function ($scope, $http,$filter) {
        datepicker($scope);
        $scope.ctrlScope=$scope;

        $scope.orderParams = {
            url: "/admin/item/getList",
            ajax:{item: '3'}
        };

        //搜索
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.item=3;
            $scope.ctrlScope.itemsearch.beginDate=$scope.ctrlScope.itemsearch.beginDateX;
            $scope.ctrlScope.itemsearch.endDate=$scope.ctrlScope.itemsearch.endDateX;

            $scope.ctrlScope.itemsearch.beginDate=$filter('date')($scope.ctrlScope.itemsearch.beginDate,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDate=$filter('date')($scope.ctrlScope.itemsearch.endDate,'yyyy-MM-dd');

            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;

            $scope.orderParams.reload();
        };

        //搜索重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch = {};
            $scope.orderParams.ajaxParam={item:3};

            $scope.orderParams.reload();
        };

        //撤回
        $scope.openViewModal=function(id){
            $scope.viewItemModal = !$scope.viewItemModal;
            $scope.ctrlScope.id=id;
        };

        //确定撤回
        $scope.submit = function(){
            var dataJson={};
            dataJson.id=$scope.ctrlScope.id;
            $http({
                method: 'POST',
                url: "/admin/item/cancel",
                data: dataJson
            }).success(function(data) {
                if(data.result=="success"){
                    toastr.success("撤回成功");
                    $scope.viewItemModal = !$scope.viewItemModal;
                    $scope.orderParams.ajaxParam={item:3};
                    $scope.orderParams.reload();
                }else{
                    if(data.messageText){
                        toastr.error(data.messageText);
                    }else{
                        toastr.error("撤回失败");
                    }

                }
            }).error(function() {
            });
        };

        //取消撤回
        $scope.cancel = function(){
            $scope.viewItemModal = !$scope.viewItemModal;
        };

    }])
});